package com.catalog.CustomComponent
{
	import Skin.Accordion.CustomAccordionContainerSkin;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.core.IVisualElement;
	
	import spark.components.Group;
	import spark.components.Scroller;
	import spark.components.SkinnableContainer;
	import spark.components.supportClasses.SkinnableComponent;
	import spark.layouts.VerticalLayout;
	
	public class CustomAccordionContainer extends SkinnableContainer
	{
		[SkinPart(required="false")]
		public var scroller:Scroller;
		
//		[SkinPart(required="false")]
//		public var contentGroup:Group;
		
		
		public function CustomAccordionContainer()
		{
			super();
			setStyle("skinClass",CustomAccordionContainerSkin);
			
			var layout:VerticalLayout = 	new VerticalLayout();
			layout.gap = 0;
			this.layout = layout;
		}
		
//		private var _accordions:Array;
//		
//		[ArrayElementType("CustomComponent.CustomAccordionContent")]
//		public function set accordions( value:Array ):void
//		{
//			_accordions = value;
//			invalidateProperties();
//			invalidateDisplayList();
//		}
//		
//		public function get accordions():Array
//		{
//			return _accordions;
//		}
//		
//		private var _currentActiveAccordion:CustomAccordionContent = null;
//
//		public function get currentActiveAccordion():CustomAccordionContent
//		{
//			return _currentActiveAccordion;
//		}
//
//		public function set currentActiveAccordion(value:CustomAccordionContent):void
//		{
//			_currentActiveAccordion = value;
//			invalidateProperties();
//			invalidateDisplayList();
//		}

//		
//		private var _selectedIndex:int = -1;
//
//		public function get selectedIndex():int
//		{
//			return _selectedIndex;
//		}
//
//		public function set selectedIndex(value:int):void
//		{
//			if( _selectedIndex != value )
//			{
//				if(	accordions.length == 0 || value == -1 || value>=accordions.length)
//				{
//					_selectedIndex = -1;
//					return;
//				}
//				for( var i:int=0;i<accordions.length;i++)
//				{
//					var accordion:CustomAccordionContent = accordions[i] as CustomAccordionContent;
//					if( i == _selectedIndex )
//					{
//						currentOpenAccordion = accordion;
//					}
//				}
//			}
//		}

		
		override protected function commitProperties():void
		{
			super.commitProperties();
//			judgementAccordionContent();
//			resetAccordingContent();
		}
		
//		private function judgementAccordionContent():void
//		{
//			for( var i:int=0;i<accordions.length;i++)
//			{
//				var accordion:CustomAccordionContent = accordions[i] as CustomAccordionContent;
//				if( contentGroup && !contentGroup.containsElement( accordion as IVisualElement ))
//				{
//					accordion.addEventListener( "openChanged",accordionOpenChangeHandler );
//					contentGroup.addElement( accordion );
//				}
//			}
//		}
		
//		private function resetAccordingContent():void
//		{
//			if( !currentActiveAccordion )
//				closeAllAccordion();
//			for( var i:int=0;i<accordions.length;i++)
//			{
//				var accordion:CustomAccordionContent = accordions[i] as CustomAccordionContent;
//				if( currentActiveAccordion && accordion != currentActiveAccordion )
//					accordion.isOpen = false;
//			}	
//		}
//		
//		/**关闭所有accordion*/
//		private function closeAllAccordion():void
//		{
//			for( var i:int=0;i<accordions.length;i++)
//			{
//				var accordion:CustomAccordionContent = accordions[i] as CustomAccordionContent;
//				accordion.isOpen = false;
//			}
//			
//		}
		
//		private function accordionOpenChangeHandler(event:Event):void
//		{
//			var accordion:CustomAccordionContent = event.currentTarget as CustomAccordionContent;
//			if( accordions.indexOf(accordion ) != -1 )
//			{
//				if( accordion.isOpen )
//				{
//					accordion.isOpen = false;
//					currentOpenAccordion = null;
//				}else
//				{
//					accordion.isOpen = true;
//					currentOpenAccordion = accordion;
//				}
//			}
//			currentActiveAccordion = accordion;
//		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
//			var h:Number = 0;
//			for( var i:int=0;i<accordions.length;i++)
//			{
//				var accordion:CustomAccordionContent = accordions[i] as CustomAccordionContent;
//				accordion.setLayoutBoundsSize( unscaledWidth,accordion.getPreferredBoundsHeight(false));
//				accordion.setLayoutBoundsPosition(0,h);
//				h+=accordion.getPreferredBoundsHeight(false);
//			}	
			
		}
	}
}